<extend name="Public:mainbase" />
<block name="content">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/dhtmlxtree.css"/>
<script language="javascript" src="__PUBLIC__/js/member.js?{:time()}"></script>  
<script language="javascript" src="__PUBLIC__/js/Validform_v5.3.2_min.js?{:time()}"></script> 
<style type="text/css">
	.Validform_checktip{line-height: 34px}
</style> 
<!--  内容列表   -->
<form name="form2" method="post">
<table width="98%" class="table table-bordered  table-hover table-condensed "  align="center">
<tr bgcolor="#E7E7E7" >
	<td height="28" colspan="11" background="__PUBLIC__/images/tbg.gif" style="padding-left:10px;">
	◆ 用户组列表 &nbsp;&nbsp;&nbsp;&nbsp;<button type="button" class="btn btn-xs btn-warning" data-toggle="modal" data-target=".newuserbox"><i class="glyphicon glyphicon-plus"></i> 添加用户组</button>
	</td>
</tr>
<tr align="center" bgcolor="#FBFCE2" height="25">
	<td width="6%">ID</td>
	<td width="4%">选择</td>
	<td width="10%">名称</td>
	<td width="10%">排序</td>
	<td width="10%">状态</td>
	<td width="10%">操作</td>
</tr>
<foreach name="groupList" item="val">
<tr align='center' bgcolor="#FFFFFF" height="26">
	<td nowrap>{$val.groupid}</td>
	<td>
		<input name="groupid" type="checkbox" value="{$val.groupid}" class="np" />
	</td>
	<td>{$val.groupname}</td>
	<td>{$val.sort}</td>
	<td><eq name="val.status" value="1">启用<else />冻结</eq></td>
	<td>
		<a href="javascript:;" data-groupid='{$val.groupid}' class='edituser'>修改</a>
		|
		<a href="javascript:;" data-groupid='{$val.groupid}' class='setGroupAuth'>设置权限</a>
		|
		<a href="javascript:;" data-groupid='{$val.groupid}' class='deluser'>删除</a>
	</td>
</tr>
</foreach>
<tr bgcolor="#ffffff">
<td height="36" colspan="11">
	&nbsp;
	<a href="javascript:selAll()" class="btn btn-xs btn-info"><i class='glyphicon glyphicon-ok'></i> 全选</a>
	<a href="javascript:noSelAll()" class="btn btn-xs btn-info"><i class='glyphicon glyphicon-remove'></i> 取消</a>
	<!-- <a href="javascript:checkArc(0)" class="btn btn-xs btn-info">&nbsp;审核&nbsp;</a> -->
	<a href="javascript:;" id="deluserall" class="btn btn-xs btn-info"><i class="glyphicon glyphicon-trash"></i> 删除</a>
</td>
</tr>
</form>
<tr align="right" bgcolor="#F9FCEF">
	<td height="36" colspan="11" align="center">
		<span>{$showpage}</span>
	</td>
</tr>
</table>

<!--  搜索表单  -->
<form name='form3' action='{:U('Admin/Group/index')}' method='get'>
<input type='hidden' name='dopost' value='listArchives' />
<table width='98%'  class='table' align="center" style="margin-top:8px">
  <tr bgcolor='#EEF4EA'>
    <td background='__PUBLIC__/images/wbg.gif' align='center'>
      <table border='0' cellpadding='0' cellspacing='0' height="32">
        <td nowrap>组名：</td>
        <td width='130'>
          	<input type='text' name='groupname' value='' style='width:120px' />
        </td>
       <td>
          <input name="imageField" type="image" src="__PUBLIC__/images/button_search.gif" width="60" height="22" border="0" class="np" />
       </td>
      </tr>
     </table>
   </td>
  </tr>
</table>
</form>


<!-- 添加组弹窗 -->
<div class="modal fade newuserbox" tabindex="-1" Auth="dialog" aria-labelledby="add_user_jump" id='newuserbox'>
  <div class="modal-dialog modal-sm" style="width:40%">
  		
    <div class="modal-content">
		<div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	        <h4 class="modal-title" id="myModalLabel">添加组信息</h4>
	    </div>
		<form action="{:U('addGroup')}" method="POST" class="form-horizontal" id="adduserform" style="padding:15px 0">
		<div class="form-group">
			<label for="username" class="col-sm-2 control-label">名称</label>
			<div class="col-sm-5">
				<input name="groupname" type="text" placeholder="请输入组名" datatype="*2-30" sucmsg=" " errormsg="用户名为2-30个字符" nullmsg="组名必须填写" class="form-control" value="">
			</div>
			<div class="col-sm-5"></div>
		</div>

		<div class="form-group">
			<label for="status" class="col-sm-2 control-label">状态</label>
			<div class="col-sm-5">
				<input id="add-status_1" name="status" type="radio" value="1" checked="checked">
				<label for="add-status_1">启用</label>&nbsp;&nbsp;
				<input id="add-status_0" name="status" type="radio" value="0">
				<label for="add-status_0">冻结</label>
			</div>
		</div>

		<div class="form-group">
			<label for="mobile" class="col-sm-2 control-label">排序</label>
			<div class="col-sm-5">
				<input name="sort" type="text" class="form-control" value="0">
			</div>
			<div class="col-sm-5"></div>
		</div>

		<div class="add-error-message error item"></div>

		<div class="form-group">
		    <div class="col-sm-offset-2 col-sm-10">
		      <button type="submit" class="btn btn-success">确定添加</button>
		      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		      <button type="button" class="btn btn-danger"  data-dismiss="modal">取消</button>
		    </div>
		  </div>
		</form>
    </div>
  </div>
</div>


<!-- 修改组弹窗 -->
<div class="modal fade edituserbox" tabindex="-1" Auth="dialog" aria-labelledby="edit_user_jump" id='edituserbox'>
  <div class="modal-dialog modal-sm" style="width:40%">
  		
    <div class="modal-content">
		<div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	        <h4 class="modal-title" id="myModalLabel">修改用户信息</h4>
	    </div>
		<form action="{:U('editGroup')}" method="POST" class="form-horizontal" style="padding:15px 0">
		<input name='groupid' type="hidden" value=''>
		<div class="form-group">
			<label for="username" class="col-sm-2 control-label">名称</label>
			<div class="col-sm-5">
				<input name="groupname" type="text" placeholder="请输入组名" datatype="*2-30" sucmsg=" " errormsg="用户名为2-30个字符" nullmsg="组名必须填写" class="form-control" value="">
			</div>
			<div class="col-sm-5"></div>
		</div>

		<div class="form-group">
			<label for="status" class="col-sm-2 control-label">状态</label>
			<div class="col-sm-5">
				<input id="edit_status_1" name="status" type="radio" value="1">
				<label for="edit_status_1">启用</label>&nbsp;&nbsp;
				<input id="edit_status_0" name="status" type="radio" value="0">
				<label for="edit_status_0">冻结</label>
			</div>
		</div>

		<div class="form-group">
			<label for="mobile" class="col-sm-2 control-label">排序</label>
			<div class="col-sm-5">
				<input name="sort" type="text" class="form-control" value="0">
			</div>
			<div class="col-sm-5"></div>
		</div>
		<div class="add-error-message error item"></div>

		<div class="form-group">
		    <div class="col-sm-offset-2 col-sm-10">
		      <button type="submit" class="btn btn-success">确定添加</button>
		      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		      <button type="button" class="btn btn-danger"  data-dismiss="modal">取消</button>
		    </div>
		  </div>
		</form>
    </div>
  </div>
</div>

<!-- 修改用户权限 -->
<div class="modal fade setuserAuthbox" tabindex="-1" Auth="dialog" aria-labelledby="set_userAuth_jump" id='setuserAuthbox'>
  <div class="modal-dialog modal-sm" style="width:320px">
  		
    <div class="modal-content"  style="height:420px">
		<div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	        <h4 class="modal-title" id="setuserAuthboxLabel">修改用户权限</h4>
	    </div>
		<div class="modal-body">
			<div id="treeboxbox_tree2"  style="width:98%;margin:0 auto; height:268px; border:1px solid #ccc;overflow:auto;"></div>
		</div>
		<div class="modal-footer">
		    <input type="hidden" id="groupid" value="" />
			<button type="button" class="btn btn-primary" id="saveAuth"><i class="glyphicon glyphicon-ok"></i> 确定</button>
        	<button type="button" class="btn btn-default" data-dismiss="modal"><i class="glyphicon glyphicon-remove"></i> 取消</button>
		</div>
    </div>
  </div>
</div>
<script src="__PUBLIC__/js/dhtmlxtree.js"></script>
<script type="text/javascript">
//myTree.load("{:U('AuthTree')}?Authlist=3,4,13,14", "json");
	$('.deluser').click(function(){
		if(confirm('是否确定删除此用户？')){
			var obj=this;
			$.get('{:U("ajaxDelGroup")}?groupid='+$(obj).data('groupid'),function(data){
				if(data.status==1){
					$(obj).parents('tr').remove();
				}
			})
		}
	})

	$('#deluserall').click(function(){
		if(confirm('是否确定删除？')){
			var id=$('[name=groupid]:checked').map(function(){
				return $(this).val();
			}).get().join()
			
			$.post('{:U("ajaxDelGroup")}', {'groupid': id},function(data){
				if(data.status == 1){
					$('[name=groupid]:checked').parents('tr').remove();
				}
			})
		}
	})

	$('#newuserbox').on('show.bs.modal', function (e) {
  		$('#newuserbox form').get(0).reset();
  		$('#newuserbox .Validform_checktip').empty().attr('class','Validform_checktip');
  		$('.Validform_error').removeClass('Validform_error');
	})
	$.ajaxSetup({cache:false})
	$('.edituser').click(function(){
		$('#edituserbox form').get(0).reset();
		$.get("{:U('ajaxGetGroupInfo')}?groupid="+$(this).data('groupid'),function(data){
  			if(data!=0){
  				$("#edituserbox [name=groupid]").val(data.groupid);
  				$("#edituserbox [name=groupname]").val(data.groupname);
  				$("#edit_status_" + data.status).get(0).checked=true;
  				$("#edituserbox [name=sort]").val(data['sort']);			
  			}
  		})
  		$('#edituserbox .Validform_checktip').empty().attr('class','Validform_checktip');
  		$('.Validform_error').removeClass('Validform_error');
		$('#edituserbox').modal('show');
	})

	$("form").Validform({
		tiptype:2,
		showAllError:true,
		datatype:{
			"zh2-30":/^[\u4E00-\u9FA5\uf900-\ufa2d]{2,30}$/
		},
	})

	function geturl($url){
		$a=$url.split('?');
		return $a[0];
	}

	var myTree = new dhtmlXTreeObject("treeboxbox_tree2","100%","100%",0);
	myTree.enableCheckBoxes(true,true);
	myTree.enableThreeStateCheckboxes(true);
	myTree.setDataMode("json");
	myTree.setImagePath("__PUBLIC__/images/dhxtree_skyblue/");

	$(".setGroupAuth").click(function(){
		myTree.deleteChildItems(0);
		myTree.load("{:U('Admin/Group/getAuthByGroup')}?groupid="+$(this).data('groupid'),"json");
		$("#groupid").val($(this).data("groupid"));
		$("#setuserAuthbox").modal('show');
	})

	$("#saveAuth").click(function(){
		if(confirm('是否确定修改此用户的权限？')){
			var idList = myTree.getAllChecked();
			$.ajax({cache:false});
			$.get("{:U('ajaxSetGroupAuth')}",{idList:idList,groupid:$("#groupid").val()},function(data){
				if(data==1){
					$("#id").val('');
					location.reload();
				}else{
					alert('修改失败！稍后重试！');
				}
			});
		}
	})
</script>




</block>